﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using nplJobsCommon.JobSeeker;
using nplJobs.DB;
using System.Data;
using nplJobsCommon;

namespace nplJobsDAL.Select
{
    public class SelectJobAlert1
    {
        public static int Insert(JobAlert obj, string strMode)
        {
            try
            {
                CustomParameterList cpList = GetParams(obj, strMode);

                object paramval = null;
                DBHelper db = new DBHelper();
                
                return db.ExecuteNonQuery(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spJobAlert");
                
               
                

            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        private static CustomParameterList GetParams(JobAlert obj, string strMode)
        {
            CustomParameterList cpList = new CustomParameterList();

            cpList.Add(new CustomParameter("ID", obj.ID, DbType.Int32));
            cpList.Add(new CustomParameter("@UserID", obj.UserID, DbType.Guid));
            cpList.Add(new CustomParameter("@AlertName", obj.AlertName, DbType.String));
            cpList.Add(new CustomParameter("@Frequency", obj.FrequencyID, DbType.Int32));
            cpList.Add(new CustomParameter("@Keyword", obj.Keyword, DbType.String));
            cpList.Add(new CustomParameter("@CategoryID", obj.CategoryID, DbType.Int32));

            cpList.Add(new CustomParameter("@LocationID", obj.LocationID, DbType.Int32));
            cpList.Add(new CustomParameter("@WorkTypeID", obj.WorkTypeID, DbType.Int32));
            cpList.Add(new CustomParameter("@SalaryRangeID", obj.SalaryRangeID, DbType.Int32));
            cpList.Add(new CustomParameter("@CreatedDate", obj.CreatedDate, DbType.DateTime));
            cpList.Add(new CustomParameter("@UpdatedDate", obj.UpdatedDate, DbType.DateTime));
            cpList.Add(new CustomParameter("@strMode", strMode, DbType.String));
            return cpList;
        }

        public static List<JobAlert> GetList(JobAlert obj)
        {
            CustomParameterList cpList = GetParams(obj, "S");

             object paramval = null;
            DBHelper db = new DBHelper();
            DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spJobAlert");

            List<JobAlert> results = new List<JobAlert>();
            foreach (DataRow dr in dt.Rows)
            {
                JobAlert objJobList = new JobAlert();

                MapperBase.GetInstance().MapItem(objJobList, dr); ;
                results.Add(objJobList);
            }
            return results;

        }

        public static List<JobListDetails> GetJobList(Guid userID, int AlertID)
        { 
         
            try
            {
                CustomParameterList cpList = new CustomParameterList();

                cpList.Add(new CustomParameter("@UserID", userID, DbType.Guid));
                cpList.Add(new CustomParameter("@AlertID", AlertID, DbType.Int32));
              

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dt = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, "spAlertJobList");

                List<JobListDetails> results = new List<JobListDetails>();
                foreach (DataRow dr in dt.Rows)
                {
                    JobListDetails objJobList = new JobListDetails();

                    MapperBase.GetInstance().MapItem(objJobList, dr); ;
                    results.Add(objJobList);
                }
                return results;

            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
    }
}
